package br.com.felix.fwt.ui;

import java.io.PrintWriter;

import br.com.felix.fwt.ui.exception.ComponentRenderException;

/**
 * The Class Input is the base class for components that will render as input.
 * No much here. Only defines constructors.
 */
public abstract class Input extends BaseComponent implements Disable{

	private static final long serialVersionUID = 9058617539617264133L;

	/** Tells if button is disabled or not. */
	private boolean disabled;
	
		
	private boolean required = false;
	
	
	/**
     * Instantiates a new input.
     */
    public Input(){
        super();
    }
    
	/**
     * Instantiates a new input.
     * 
     * @param value the value
     */
    public Input(String value){
        super(value);
    }
    
	/* (non-Javadoc)
	 * @see br.com.felix.fwt.ui.BaseComponent#write(java.io.PrintWriter)
	 */
	public abstract void write(PrintWriter out) throws ComponentRenderException ;

	
	public boolean isRequired() {
		return required;
	}

	
	public void setRequired(boolean required) {
		this.required = required;
	}

	
	@Override
	public boolean validate() {
		if(isRequired()){
		    String value = getValue();
			return value == null || value.length()==0;
		}
		return true;
	}
	
	
	public void setDisabled(boolean disabled) {
		this.disabled = disabled;
	}


	public boolean isDisabled() {
		return disabled;
	}
	
	/**
     * @see BaseComponent#isInputControl()
     * */
	@Override
    public boolean isInputControl(){
        return true;
    }

}
